#!/usr/bin/env python2.6

import re
import urllib
from BeautifulSoup import BeautifulSoup
import Growl

name = "MyBonk"   # was BonkMe
notifications = ["search_hit"]
notifier = Growl.GrowlNotifier(name,notifications)
notifier.register()

# Read file of search Terms
myTerms = open("/Users/bmiller/lib/bonk_items.txt").readlines()


# Get the latest page
bt = urllib.urlopen("http://www.bonktown.com")

doc = BeautifulSoup(bt.read())

itemlist = doc.findAll(id=re.compile("item_title"))
price = doc.findAll(id=re.compile("price"))
desc = doc.findAll(id=re.compile("item_description"))

for term in myTerms:
    for i in range(len(itemlist)):
        if itemlist[i] and re.search(term[:-1],itemlist[i].contents[0],re.IGNORECASE):
            notifier.notify("search_hit",
                            itemlist[i].contents[0],
                            desc[i].contents[7].contents[0],
                            sticky=False)


